package com.zbb.exam_system.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //指定哪个包下的控制器类要生成对应的接口文档
                .apis(RequestHandlerSelectors.basePackage("com.zbb.exam_system.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("考试系统RESTful接口")
                .description("考试系统接口文档")
                // 服务条款网址 http://127.0.0.1:8888/swagger-ui.html
                .termsOfServiceUrl("http://127.0.0.1:8888/swagger-ui.html")
                .version("1.0")
                // 许可证
                .license("exam_system")
                .contact(new Contact("xxx", "http://www.baidu.com", "xxx$xx.com"))
                .build();
    }
}
